package com.google.gwt.sample.stockwatcher.client;

import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.EventListener;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.FlexTable;

public class MyFlexTable extends FlexTable implements EventListener {

	public MyFlexTable() {
		super();

		sinkEvents(Event.ONCLICK | Event.ONDBLCLICK | Event.ONKEYDOWN);
	}

	public void onBrowserEvent(Event event) {
		Element td = this.getEventTargetCell(event);
		if (td == null) {
			return;
		}
		// Element tr = td.getParentElement();
		// Element body = tr.getParentElement();
		Element tr = DOM.getParent(td);
		Element body = DOM.getParent(tr);

		int row = DOM.getChildIndex(body, tr);
		int column = DOM.getChildIndex(tr, td);

		switch (DOM.eventGetType(event)) {
			case Event.ONDBLCLICK: {
				//this.removeRow(row);
				Window.alert("DB " + row +"/" + this.getDOMRowCount());
				break;
			}
			case Event.ONMOUSEOVER:
			{
				Window.alert("DB " + row);
				break;
			}
			default: {
				// Do nothing
			}
		}
		
	}
}
